/*
Copyright (C) 2013 Bengt Martensson.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or (at
your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program. If not, see http://www.gnu.org/licenses/.
*/

package org.harctoolbox.irscrutinizer.importer;

import java.util.Date;
import java.util.HashMap;
import org.harctoolbox.IrpMaster.DecodeIR;
import org.harctoolbox.girr.Remote;
import org.harctoolbox.girr.RemoteSet;
import org.harctoolbox.irscrutinizer.Utils;
import org.harctoolbox.irscrutinizer.Version;

/**
 * This class does something interesting and useful. Or not...
 */
public abstract class RemoteSetImporter extends ReaderImporter implements IRemoteSetImporter {
    protected RemoteSet remoteSet = null;

    protected RemoteSetImporter() {
        super();
    }

    @Override
    public RemoteSet getRemoteSet() {
        return remoteSet;
    }

    protected Remote setupRemote() {

        HashMap<String, HashMap<String, String>> appParams = new HashMap<>();
        appParams.put(getClass().getSimpleName(), null);
        Remote remote = new Remote(Utils.basename(origin),
                null, // manufacturer,
                null, // model,
                null, // deviceClass,
                null, // String remoteName,
                null, //String comment,
                null,
                getCommandIndex(),
                appParams);
        return remote;
    }

    protected void setupRemoteSet(Remote remote) {
        remoteSet = new RemoteSet(getCreatingUser(),
                origin, //java.lang.String source,
                (new Date()).toString(), //java.lang.String creationDate,
                Version.appName, //java.lang.String tool,
                Version.version, //java.lang.String toolVersion,
                DecodeIR.appName, //java.lang.String tool2,
                DecodeIR.getVersion(), //java.lang.String tool2Version,
                "Generated by " + getClass().getCanonicalName(), //java.lang.String notes,
                remote);
    }

    protected void setupRemoteSet() {
        setupRemoteSet(setupRemote());
    }

    protected void setupCommands() {
        clearCommands();
        for (Remote remote : remoteSet.getRemotes()) {
            addCommands(remote.getCommands().values());
        }
    }
}
